<template>
  <div class="detail">
    <span @click="returngo" class="returngo">
      💫
    </span>
    <div class="swipers">
      <div class="lb">
        <div id="my-swiper">
          <ul
            @touchstart="touchStart"
            @touchmove="touchMove"
            @touchend="touchEnd"
            :style="activeStyle"
          >
            <li v-for="(item, index) in swipers" :key="index">
              <img :src="item.pic" alt="" />
            </li>
          </ul>
        </div>
      </div>
      <div class="content">
        <p v-html="contents.name" class="cp"></p>
        <p class="cps">{{ contents.characteristic }}</p>
        <p class="price">
          <span class="red">低价{{ "￥" + contents.minPrice }}</span>
          <span class="center">原价{{ "￥" + contents.originalPrice }}</span>
          <span class="right">库存{{ contents.recommendStatus }}</span>
        </p>
      </div>
    </div>
    <div class="obsve">
      <div class="djs">
        <span @click="yss" class="ss1">商品介绍</span>
        <span @click="ycc" class="ss2">
          商品评价
        </span>
      </div>
      <ul>
        <li>
          <div class="js" v-show="ys">
            <div v-html="text"></div>
          </div>
        </li>
        <li>
          <div class="pj" v-show="yc">
            <div id="navs" v-for="(item, index) in comment" :key="index">
              <div class="touxiang">
                <i class="iconfont icon-touxiang"></i>
              </div>
              <div class="pl">
                <p class="tops">
                  {{ item.goods.goodReputationRemark }}
                  {{ item.goods.goodReputationRemark ? "" : "匿名用户" }}
                  <button>{{ item.goods.goodReputationStr }}</button>
                </p>
                <p class="bottoms">
                  {{ item.goods.dateReputation }}
                  <span
                    >选择规格 <span v-html="item.goods.goodsName"></span>
                  </span>
                </p>
              </div>
            </div>
          </div>
        </li>
      </ul>
    </div>
    <div class="button">
      立即发起砍价,最低可砍到一元
    </div>
  </div>
</template>

<script>
import { getKanjiashop } from "../../utils/api";
import { getreputation } from "../../utils/api";
export default {
  data() {
    return {
      activeStyle: {
        transition: "none",
        left: "-100%",
      },
      dir: "left", // 标记用户滑动的方向
      startPos: 0, // 记录用户触摸的开始点
      isWork: true, // 标记动画是否能够执行
      swipers: [],
      contents: "",
      comment: [],
      ys: true,
      yc: false,
      text: "",
    };
  },
  mounted() {
    let id = Number(this.$route.query.id);
    getKanjiashop(id).then((res) => {
      this.swipers = res.data.pics;
      this.contents = res.data.basicInfo;
      console.log(res);
      this.text = res.data.content;
    });
    setInterval(() => {
      this.touchEnd();
    }, 1000);
    //评论
    getreputation(id).then((res) => {
      console.log(res);
      this.comment = res.data;
    });
  },
  methods: {
    //显示
    yss() {
      (this.ys = true), (this.yc = false);
    },
    ycc() {
      (this.yc = true), (this.ys = false);
    },
    returngo() {
      this.$router.go(-1);
    },
    touchStart(e) {
      this.startPos = e.touches[0].pageX;
    },
    touchMove(e) {
      if (e.touches[0].pageX - this.startPos > 0) {
        this.dir = "right";
      } else {
        this.dir = "left";
      }
    },
    touchEnd() {
      if (this.isWork) {
        this.isWork = false;
        if (this.dir == "right") {
          this.activeStyle = {
            transition: "left 1s",
            left: "0",
          };

          setTimeout(() => {
            let item = this.swipers.pop();
            this.swipers.unshift(item);
            this.activeStyle = {
              transition: "none",
              left: "-100%",
            };
            this.isWork = true;
          }, 1000);
        } else {
          this.activeStyle = {
            transition: "left 1s",
            left: "-200%",
          };

          setTimeout(() => {
            let item = this.swipers.shift();
            this.swipers.push(item);
            this.activeStyle = {
              transition: "none",
              left: "-100%",
            };
            this.isWork = true;
          }, 1000);
        }
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.detail {
  width: 100%;
  height: 100%;
}
* {
  margin: 0 !important;
  padding: 0;
}
.returngo {
  font-size: 0.7rem;
  position: absolute;
  z-index: 9999;
  top: 0.5rem;
}
.swipers {
  width: 100%;
  height: 10rem;
  .lb {
    width: 100%;
    height: 8rem;
    overflow: hidden;
    #my-swiper {
      width: 100%;
      text-align: center;
      ul {
        width: 500%;
        height: 8rem;
        position: relative;
        > li {
          width: 20%;
          height: 8rem;
          float: left;
          text-align: center;
          img {
            width: 100%;
            height: 100%;
          }
        }
      }
    }
  }
  .content {
    width: 100%;
    height: 2.1rem;
    border-bottom: 0.14rem solid #f5f5f5;
    .cp {
      font-size: 0.35rem;
      padding: 0rem 0 0.2rem 0.2rem;
      box-sizing: border-box;
    }
    .cps {
      padding-left: 0.2rem;
      font-size: 0.3rem;
      color: #b8b8b8;
    }
    .price {
      padding-left: 0.2rem;
      display: flex;
      justify-content: space-between;
      padding-top: 0.2rem;
      .red {
        color: red;
      }
      .right {
        display: block;
        padding-right: 0.2rem;
        color: #b8b8b8;
      }
      .center {
        color: #b8b8b8;
      }
    }
  }
}
.obsve {
  width: 100%;
  padding-top: 0.5rem;
  position: relative;
  .djs {
    width: 100%;
    display: flex;
    justify-content: space-around;
    .ss1 {
      display: block;
      height: 0.5rem;
      font-size: 0.35rem;
    }
    .ss2 {
      display: block;
      height: 0.5rem;
      font-size: 0.35rem;
    }
  }
}
/deep/ .m-attrList {
  width: 100%;
  height: 100%;
  .list-paddingleft-2 {
    width: 100%;
  }
}
ul {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  li {
    font-size: 0.35rem;
    width: 100%;
    margin-top: 0.2rem;
    .js {
      width: 100%;
      position: absolute;
      left: 0;
    }
    .pj {
      width: 100%;
      position: absolute;
      left: 0;
      #navs {
        display: flex;
        justify-content: space-between;
        height: 2.5rem;
        border-bottom: 1px solid #cccccc;
        .touxiang {
          width: 2rem;
          height: 100%;
          i {
            text-align: center;
            font-size: 1rem;
            display: inline-block;
            line-height: 2rem;
            padding-left: 0.35rem;
          }
        }
        .pl {
          width: 6rem;
          height: 100%;
          // background: yellowgreen;
          .tops {
            width: 100%;
            height: 1rem;
            //   background: chartreuse;
            font-size: 0.3rem;
            line-height: 1rem;
            button {
              background: red;
              color: white;
              border: none;
              outline: none;
              // width: 1rem;
              height: 0.5rem;
              border-radius: 0.2rem;
            }
          }
          .bottoms {
            width: 100%;
            height: 1rem;
            font-size: 0.2rem;
            color: #cccccc;
            line-height: 1.2rem;
          }
        }
      }
    }
  }
}
.button {
  width: 100%;
  height: 0.8rem;
  position: fixed;
  color: white;
  bottom: 0;
  background: #b7282e;
  text-align: center;
  line-height: 0.8rem;
}
/deep/ .img-lazyloaded {
  width: 100% !important;
  height: 100% !important;
}
/deep/ .short {
  width: 100% !important;
  height: 100% !important;
}
</style>
